<!--
 * @description  :驾驶员信息
 * @descriptionDetail:驾驶员信息
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-10-31 15:37:01
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999"></theme-navbar>
    <!-- #endif -->
    <view class="content content-bg ifn-content" style="background-color: white">
      <u-form
        class="u-form-m"
        :label-style="labelStyle"
        :model="baseInfo"
        :error-type="['border-bottom', 'message',]"
        label-width="auto"
        label-position="top"
        ref="uForm"
      >
        <u-form-item label="驾驶员姓名" :required="true" prop="name">
          <u-input
            v-model="baseInfo.name"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="证件类型" :required="true" prop="idCardType">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.IDCARD_TYPE"
            :dicCode="baseInfo.idCardType"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('carStyle',$u.dic.DIC_KEYS.IDCARD_TYPE)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.idCardTypeName"
            @changeInputModelData="(name)=>{$set(baseInfo, 'idCardTypeName', name)}"
            @click="showDic($u.dic.DIC_KEYS.IDCARD_TYPE,baseInfo.idCardType,'carStyle')"
          />
        </u-form-item>
        <u-form-item label="证件号码" prop="idCard" :required="true">
          <u-input
            v-model="baseInfo.idCard"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="驾驶证号" prop="driverLicNo" :required="true">
          <u-input
            v-model="baseInfo.driverLicNo"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="是否伪装">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.S_SYS_YES_NO"
            :dicCode="baseInfo.pretend"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('pretend',$u.dic.DIC_KEYS.S_SYS_YES_NO)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.pretendStr"
            @changeInputModelData="(name)=>{$set(baseInfo, 'pretendStr', name)}"
            @click="showDic($u.dic.DIC_KEYS.S_SYS_YES_NO,baseInfo.pretend,'pretend')"
          />
        </u-form-item>
      </u-form>
    </view>
    <view class="submit-btns btn-other-cls" v-if="from == 'edit'" style="bottom:0rpx">
      <u-button plain class="u-btn" type="error" @click="deleteInfo">
        删除
      </u-button>
      <u-button class="u-btn" type="primary" @click="submit">
        保存
      </u-button>
    </view>
    <view class="submit-btns bottom-btns " v-if="from != 'edit'">
      <u-button class="del" type="primary" @click="submit">
        保&nbsp;&nbsp;&nbsp;&nbsp;存
      </u-button>
    </view>
    <!-- 字典单选 -->
    <dic-choice
      :keyWord="dicKeyWords"
      :currentSelect="dicCurrentSelect"
      v-model="dicShow"
      @confirm="selectDicConfirm"
    ></dic-choice>
  </view>
</template>

<script>
import DicInput from "@/components/dic_input.vue";
import DicChoice from "@/components/dic_choice.vue";
import intelligenceservice from "@/service/intelligence/intelligence.service";
import {uuid,} from '@/common/util.js';
import {L_BSC_IDCARD_TYPE,} from "@/service/intelligence/mapping/enum.js";
export default {
  components: {
    DicChoice,DicInput,
  },
  data() {
    return {
      customStyle:{
        padding:"20rpx 32rpx",
      },
      fileUploadParam:{
        fiGroupCode:this.$FILE_GROUP_TYPE.k_transport_attr,
        bizId:"",
      },
      rules:{
        name: [{
          required: true,
          message: '请输入姓名',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },{
          message:"姓名格式不正确！",
          trigger: ['change', 'blur',],
          validator: (rule, value, callback) => {
            if(this.$u.test.isEmpty(value)){
              return true;
            }{
              let regs = /^[a-zA-Z\u4e00-\u9fa5]+$/;
              return regs.test(value);
            }
          },
        },],
        idCardType: [{
          required: true,
          message: '请选择证件类型',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },],
        idCard: [{
          required: true,
          message: '请输入证件号码',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },{
          message:"证件格式不正确！",
          trigger: ['change', 'blur',],
          validator: () => {
            if (this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.IDCARD) {
              // 身份证号
              let regs = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/;
              return regs.test(this.baseInfo.idCard);
            }else if(this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.PASSPORT){
              // 护照
              let regs = /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/;  // 护照（包括香港和澳门）
              return regs.test(this.baseInfo.idCard);
            }else if(this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.OTHER){
              // 其他证件
              let regs = /^[0-9a-zA-Z]*$/;
              return regs.test(this.baseInfo.idCard);
            }else if(this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.DRIVER){
              // 驾照
              let regs = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}(\d|x|X)$/;
              return regs.test(this.baseInfo.idCard);
            }else if(this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.RESIDENCE_BOOKLET){
              // 户口簿
              let regs = /^[a-zA-Z0-9]{3,21}$/;
              return regs.test(this.baseInfo.idCard);
            }else{
              return true;
            }
          },
        },],
        driverLicNo: [{
          required: true,
          message: '请输入驾驶证号',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },{
          message:"驾驶证号格式不正确！",
          trigger: ['change', 'blur',],
          validator: (rule, value, callback) => {
            let regs = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}(\d|x|X)$/;
            return regs.test(this.baseInfo.driverLicNo);
          },
        },],
      },
      baseInfo: {
        name: "",
        idCardType: "",
        idCard:"",
        uuid: "",
        type:"1",
      },
      labelStyle: {
        fontWeight: 400,
        color: this.$theme.u_main_color,
        fontSize: '.75rem',
      },
      iconstlye: {
        'fontSize': '40rpx',
        'color': this.$theme.u_type_primary,
      },
      fileList:[],
      orgSelectShow: false,
      dicKeyWords: "",
      dicCurrentSelect:"",
      dicShow: false,
      user: this.$storage.get(this.$rp.common.USER),
      isDisabled:false,
      tranStatus: false, // 运输类型判断下面表单是否显示
      detailList:[],
    }
  },
  onLoad(opt) {
    this.from = opt.from;
    if(this.from === "edit"){
      this.isDisabled = false;
      this.baseInfo = this.getRouteParam();
    }else {
      this.baseInfo.uuid = uuid();
    }
  },
  onReady() {
    this.$refs.uForm.setRules(this.rules);
    this.getListViewTop();
  },
  mounted(){
  },
  methods: {
    getListViewTop(){
      this.$u.getRect('.case-search-lay').then(res => {
        this.listViewTop = (this.$u.sys().statusBarHeight + res.top + res.height) + 'px';
      });
      this.$u.getRect('.submit-btns').then(res => {
        this.bottomOffset = (this.$u.sys().screenHeight - res.top) + "px";
      });
    },
    handlerChooseOrg(orgs) {
      this.baseInfo.orgUuid = orgs[0].id;
      this.baseInfo.orgName = orgs[0].name;
      this.orgSelectShow = false;
    },
    selectDicConfirm(e) {
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.IDCARD_TYPE) { // 证件类型
        this.baseInfo.idCardTypeName = e[0].label;
        this.baseInfo.idCardType = e[0].extra.bcbCode;
      }
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.S_SYS_YES_NO) { // 是否伪装
        this.baseInfo.pretendStr = e[0].label;
        this.baseInfo.pretend = e[0].extra.bcbCode;
      }
    },
    dicSelectOpen(type, keyWords) {
      if (type == this.dicType) {
        if (this.dicKeyWords == keyWords && this.dicShow) {
          return true;
        }
        return false;
      }
    },
    showDic(key, cur, type) {
      if (this.dicShow) return;
      this.dicKeyWords = key;
      this.dicCurrentSelect = cur;
      this.dicShow = true;
      this.dicType = type;
    },
    deleteInfo () {
      this.backPrev({
        paramKey:'delRefresh',
        param:this.baseInfo.deleteIndex,
      })
    },
    submit(){
      this.$refs.uForm.validate(valid => {
        if (valid) {
          let params = this.baseInfo;
          this.backPrev({
            paramKey:'refresh',
            param:params,
          })
        } else {
          console.log('验证失败');
        }
      });

    },
  },

}
</script>

<style scoped lang="scss">
@import "../intelligenceFilesAdd/add.scss";
</style>
